package com.method;

import java.util.Scanner;

/*
要写注释哦!!!
*/
public class Demo10 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9};
        System.out.println("请输入你要找的数：");
        int rmnum = sc.nextInt();
        int resout = numbetId(arr, rmnum);
        if (resout != -1) {
            System.out.println(rmnum + "的索引位置为：" + resout);
        }
    }

    public static int numbetId(int[] arr, int rmnum) {
        int index = -1;
        for (int i = 0; i < arr.length; i++) {
            if (rmnum == arr[i]) {
                index = i;
            }
        }
        if (index == -1) {
            System.out.println("你查的数不存在！");
            return -1;
        }
        return index;
    }
}
